package com.blogs.service;

import com.blogs.entity.AppConfig;
import com.blogs.entity.MsgEntity;
import com.blogs.service.GetMsgTask.onTaskCallBack;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

public class DeleteComment {
	public interface IMsgCallBack {
		public void onSuccess();

		public void onFailed(String err);
	}

	private String url = AppConfig.DELETE_COMMENT;
	private GetMsgTask getresult;
	private IMsgCallBack callback;

	public DeleteComment(String sid, String commentId, IMsgCallBack callback) {
		this.callback = callback;
		url = url.replace("{0}", sid).replace("{1}", commentId);
		getresult = new GetMsgTask(taskCallBack);
	}

	public void Del() {
		getresult.execute(url);
	}

	private GetMsgTask.onTaskCallBack taskCallBack = new onTaskCallBack() {

		public void onSuccess(String result) {
			// TODO Auto-generated method stub
			GsonBuilder builder = new GsonBuilder();
			Gson gson = builder.create();
			MsgEntity<String> msg = null;
			try {
				msg = gson.fromJson(result, MsgEntity.class);
			} catch (Exception e) {
				callback.onFailed("服务器错误");
				return;
			}
			if (msg.data.equals("1")) {
				callback.onSuccess();
			} else  {
				callback.onFailed("服务器错误");
			}
		}

		public void onFailed() {
			// TODO Auto-generated method stub
			callback.onFailed("网络错误");
		}
	};
}
